<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<%@page import="support.*, java.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Discipline Analytics</title>
</head>
<body>
    <!-- Display all of the Disciplines -->
    Click on the number to choose a discipline:
    <%
    // Connect to ConnectionPool
    Connection conn = null;
    try{
        Context initCtx = new InitialContext();
        DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/CS135");
        conn = ds.getConnection();
    }finally{
    }
    Statement stmt = conn.createStatement();
  
    // use sql statement to display all the specializations
    ResultSet rset = stmt.executeQuery("SELECT  a.dname, COUNT(b.discipline) AS \"Number of applicants in discipline\" FROM disciplines a LEFT OUTER JOIN degrees b ON a.dname = b.discipline GROUP BY a.dname ORDER BY a.dname");
    %>
    <table>
    <% // print out results in table
    while(rset.next()){ %>
      <tr>
        <!-- Name of Specialization -->
        <td>
          <%
             out.print(rset.getString(1) + "<br>");
          %>
        </td>
        <!--  Number of students taking the class -->
        <td>
            <% out.print("<a href=\"../application.jsp?analytic=discipline&category=" + rset.getString(1) + "\">"); %>
            <% out.print(rset.getInt(2) + "</a>"); %>
        </td>
      </tr>
    <% } %>
    </table>
</body>
</html>